package cn.doitedu.eagle.ruleutils;

import cn.doitedu.eagle.beans.RuleParamEvent;

import java.util.List;
import java.util.Map;

public class RuleParamUtil {

    private static StringBuffer sb = new StringBuffer();
    private static StringBuffer sb2 = new StringBuffer();

    /**
     * 将规则条件对象转成str格式
     * @param eventParam
     * @return e1-p1-v1-p2-v2
     */
    public static String ruleEventParam2Str(RuleParamEvent eventParam){
        String eventId = eventParam.getEventId();
        sb.append(eventId);

        Map<String, String> properties = eventParam.getProperties();
        for (String key : properties.keySet()) {
            sb.append("-");
            sb.append(key);
            sb.append("-");
            sb.append(properties.get(key));
        }
        String s = sb.toString();
        sb.delete(0,sb.length());
        return s;
    }


    public static String ruleEventParamList2Str(List<RuleParamEvent> seqParamList, String deviceId){

        sb2.append(deviceId);
        for (RuleParamEvent ruleParamEvent : seqParamList) {
            sb2.append(",");
            sb2.append(ruleEventParam2Str(ruleParamEvent));
        }

        String s = sb2.toString();
        sb2.delete(0,sb2.length());
        return s;
    }



}
